import { ref } from 'vue'
import { defineStore } from 'pinia'
import { layoutDefaultInfo, type sizeConfig } from '@/components/layout/config'
import { setComponentsSize } from '@/utils/common'

export const useLayoutStore = defineStore('layoutConfig', () => {
  const currLayout = ref(4)
  const currLayoutInfo = ref<sizeConfig>()
  // 更新布局
  function updateLayout(layout:number, sizeConfig: sizeConfig) {
    currLayout.value = layout
    currLayoutInfo.value = sizeConfig
    setComponentsSize(layout, sizeConfig)
  }
  // 重置布局
  function resetLayout(layout?:number) {
    currLayout.value = layout || 4
    const deafaultInfo = layoutDefaultInfo.filter((item:any) => item.type === currLayout.value)[0]
    currLayoutInfo.value = {...deafaultInfo}
    setComponentsSize(currLayout.value, currLayoutInfo.value)
  }
  return { currLayout, currLayoutInfo, updateLayout, resetLayout }
},{
  persist: true
})
